package com.hoyue.interact.controller;


import com.hoyue.classroom.service.CourseService;
import com.hoyue.interact.bean.UserReply;
import com.hoyue.interact.service.CommentService;
import com.hoyue.interact.service.ReplyService;
import com.hoyue.system.bean.User;
import com.hoyue.system.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/reply")
public class ReplyController {

    @Autowired
    CommentService commentService;


    @Autowired
    UserService userService;

    @Autowired
    CourseService courseService;

    @Autowired
    ReplyService replyService;

    private String prefix = "interact";

    @ResponseBody
    @RequestMapping(value = "/radd",method = RequestMethod.POST)
    public int insertReply(String replycontent, Integer commentId, ModelMap modelMap, HttpSession session) {

        // 查询当前登录的用户信息
        User user = userService.getLoginUser();
        int replyId=replyService.insertReply(replycontent, String.valueOf(user.getId()),user.getUserName(),commentId);
        UserReply userReply = new UserReply(user.getId(),replyId,commentId);
        session.setAttribute("commentid",commentId);
        return replyService.addReply(userReply);
    }

    @GetMapping("/reply/{id}")
    public String reply(ModelMap modelMap, @PathVariable(value = "id") Integer id) {
     //   Matter matter = matterService.getMatter(id);
        System.out.println(id);
        //model.addAttribute("id",id);
        modelMap.put("id",id);
        return prefix + "/reply";
    }





}